package com.xunshibao.action;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class DefaultJHtmlController {

    @RequestMapping(value = "/**/*.jhtml")
    public ModelAndView jhtml(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/html;charset=UTF-8");
        String servletPath = request.getServletPath();
        String url = request.getRequestURI();
        int start = url.indexOf(servletPath) + servletPath.length() + 1;
        url = url.substring(start, url.length() - ".jhtml".length());
        return new ModelAndView(url);
    }

    @RequestMapping(value = "/xd_receiver.html")
    public void renren(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/xd_receiver.html").forward(request, response);
    }

    @RequestMapping(value = "/xd.html")
    public void sina(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/xd.html").forward(request, response);
    }
}
